﻿using System;
using System.Runtime.InteropServices;
using System.Security;

namespace AwesomiumDotNet
{
    /// <summary>
    /// A WebView is similiar to a "tab" in a browser. You load pages into a 
    /// WebView, interact with it, and render it on-the-fly to a pixel buffer 
    /// (e.g., for use in an image/texture/etc). You create WebViews using the 
    /// WebCore (see WebCore.CreateWebView).
    /// </summary>
    public class WebView : IDisposable
    {
        unsafe internal WebView(__WebViewClass* webView)
        {
            unmanaged = webView;
        }

        /// <summary>
        /// Destroys the WebView instance.
        /// </summary>
        public void Dispose()
        {
            unsafe
            {
                //call destructor
                //WebView_Dtor(_cpp);
            }
        }

        /// <summary>
		/// Loads a URL into the WebView asynchronously.
		/// </summary>
		/// <param name="url">
		/// The URL to load.
		/// </param>
		public void LoadUrl (string url)
        {
            unsafe
            {
                wstring urlTemp = new wstring(url);
                WebView_LoadUrl(unmanaged, &urlTemp);
                urlTemp.Free();
            }
        }

        internal unsafe struct __WebViewClass
        {
        }

        unsafe __WebViewClass* unmanaged;

        [DllImport("Awesomium", EntryPoint = "??_FWebCore@Awesomium@@QAEXXZ", CallingConvention = CallingConvention.ThisCall), SuppressUnmanagedCodeSecurityAttribute]
        unsafe extern static IntPtr WebView_LoadUrl(__WebViewClass* inst, wstring* url);
    }
}
